package cn.bitkit.component.exception;

import cn.bitkit.base.constants.BasicApiCode;
import cn.bitkit.base.container.ApiResponse;
import cn.bitkit.base.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public ApiResponse<String> doException(Exception e) {
        return ApiResponse.fail(BasicApiCode.FAIL.desc);
    }

    @ExceptionHandler(BusinessException.class)
    public ApiResponse<String> doBasicException(BusinessException e) {
        return ApiResponse.fail(e.getErrorCode(), e.getErrorMsg());
    }

}
